package educar.gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.LayoutManager;
import java.sql.SQLException;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;

//import com.jgoodies.forms.factories.CC;
import educar.controllers.ActividadControllerDoc;
import educar.controllers.CorreccionController;
import educar.controllers.DatosActController;
import educar.controllers.DatosController;
import educar.controllers.IController;
import educar.controllers.LoginController;
import educar.controllers.MateriaController;
import educar.controllers.MateriaInscripcionController;
import educar.db.JPA;
import educar.models.Session;

public class InscripcionView extends JPanel implements IView {
     JFrame jfWindow;
    JLabel label1;
    JLabel label2;
    JTextField textField1;
     JButton button1;
     JButton button2;
     javax.swing.JComboBox jComboBox1;
     javax.swing.JComboBox jComboBox2;
     String nomMat [];
     String codMat[];
    public InscripcionView() {
        jfWindow = new JFrame();
        Container container = jfWindow.getContentPane();

        setupMainContainer(container);

        jfWindow.pack();
        jfWindow.setVisible(true);
        jfWindow.setResizable(false);
        jfWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }

    private void setupMainContainer(Container container) {
        container.setLayout((LayoutManager) new BoxLayout(jfWindow
                .getContentPane(), BoxLayout.Y_AXIS));

        ((JComponent) container).setBorder(new EmptyBorder(20,70,70, 70));

        JLabel lblWelcome = new JLabel(" Seleccione materia disponible ");
        lblWelcome.setAlignmentX(Component.CENTER_ALIGNMENT);
        lblWelcome.setFont(new Font("Serif", Font.BOLD, 20));
        lblWelcome.setBorder(new EmptyBorder(0, 10, 10, 10));
        container.add(lblWelcome);
        
        
        
        JPA jpa = new JPA();
        try {
        nomMat =jpa.getConsulta("materia", "nombre", "codigo=codigo");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(nomMat));
           jComboBox1.setName("jComboBox1"); 
           JPanel usernamePane2 = new JPanel();
            usernamePane2.setLayout(new BoxLayout(usernamePane2, BoxLayout.LINE_AXIS));
            usernamePane2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));                    
            usernamePane2.add(jComboBox1);                    
            container.add(usernamePane2);

            try {
                codMat =jpa.getConsulta("materia", "codigo", "nombre= '"+this.getMateria() +"'");
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                JLabel label2 = new JLabel("Codigo"); 
                jComboBox2 = new javax.swing.JComboBox();
                jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(codMat));
                   jComboBox2.setName("jComboBox2"); 
                   JPanel usernamePane1 = new JPanel();
                    usernamePane1.setLayout(new BoxLayout(usernamePane1, BoxLayout.LINE_AXIS));
                    usernamePane1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));                    
                    usernamePane1.add(label2);
                    usernamePane1.add(jComboBox2);                    
                    container.add(usernamePane1);          
        
        //---- button1 ----
                
        
        JButton binscripcion = new JButton("Inscribirse");
        binscripcion.setFont(new Font("Serif", Font.BOLD, 15));
        binscripcion.setAlignmentX(CENTER_ALIGNMENT);
            container.add(binscripcion);
            
            LoginListener buttonListener = new LoginListener();
            IController loginController = new MateriaInscripcionController();
            loginController.setView(this);
            buttonListener.associate(binscripcion, loginController);
            
    
        
        
    }
    
    
     
     public void present(String model) {
            JOptionPane.showMessageDialog(null, model);
        }

     public String getMateria(){
            
         return (String) jComboBox1.getSelectedItem();
     }     
     public String getCodigo(){
            
         return (String) jComboBox2.getSelectedItem();
     }      
     

    
    public static void main(String args[]) {
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception ex) {
                    // ignore
                }
               javax.swing.JFrame frame = new javax.swing.JFrame("Datos");
                frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                frame.getContentPane().add(new InscripcionView());
                frame.pack();
                frame.setVisible(false);
              
               
            }
        });
    }
    
    
}